package com.woniu.smart.controller;


import com.github.pagehelper.PageInfo;
import com.woniu.smart.dto.CustomerDTO;
import com.woniu.smart.entity.SysAdmin;
import com.woniu.smart.service.CustomerService;
import com.woniu.smart.service.SysAdminService;
import com.woniu.smart.util.Result;
import com.woniu.smart.vo.CustomerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：mmzs
 * @description：客户管理模块
 * @date ：2022/10/24 19:36
 */
@RestController
@RequestMapping("customers")
public class CustomerController {

    @Autowired
    private CustomerService customerService;
    @Autowired
    private SysAdminService sysAdminService;
    @PostMapping
    public Result selAll(@RequestBody CustomerDTO customerDTO){
        List<CustomerVO> customerVOS = customerService.selectAll(customerDTO);
        PageInfo<CustomerVO> list = new PageInfo<>(customerVOS);
        return Result.ok().data("customerList",list);
    }
    @DeleteMapping("{id}")
    public Result del(@PathVariable Long id){
        int i = customerService.deleteByPrimaryKey(id);
        return Result.ok();
    }
    @PostMapping("delAll")
    public Result delAll(@RequestBody Long[] ids){
        int i = customerService.deleteAll(ids);
        return Result.ok();
    }
    @PostMapping("add")
    public Result add(@RequestBody CustomerVO customerVO){
        int i = customerService.insertSelectiveCustomer(customerVO);
        return Result.ok();
    }
    @GetMapping("{customerId}")
    public Result selByCustomerId(@PathVariable Long customerId){
        CustomerVO customerVO = customerService.selectByCustomerId(customerId);
        return Result.ok().data("customerVO",customerVO);
    }
    //根据园区员工姓名查找园区员工电话
    @PostMapping("{empName}")
    public Result selEmpTel(@PathVariable String empName){
        SysAdmin sysAdmin = sysAdminService.selectEmpTelByEmpName(empName);
        return Result.ok().data("sysAdmin",sysAdmin);
    }
    @PutMapping
    public Result updateByCustomerId(@RequestBody CustomerVO customerVO){
        int i = customerService.updateByPrimaryKeySelectiveAll(customerVO);
        return Result.ok();
    }


}
